package com.qire.manhua.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.qire.antscore.annotation.RouteMapping;
import com.qire.antsrouter.inject.Autowired;
import com.qire.common.basic.ObjectUtil;
import com.qire.common.constant.Navigation;
import com.qire.common.inject.EventControllerInjector;
import com.qire.common.inject.ViewModelInjector;
import com.qire.common.support.base.BaseActivity;
import com.qire.common.utils.ThemeUtil;
import com.qire.manhua.R;
import com.qire.manhua.controller.BulletScreenDialogController;
import com.qire.manhua.databinding.ActivityBulletScreenDialogBinding;
import com.qire.manhua.model.viewModel.impl.BulletScreenDialogViewModel;

import net.yslibrary.android.keyboardvisibilityevent.util.UIUtil;


import androidx.annotation.Nullable;

@RouteMapping(path = Navigation.Page.BulletScreenDialogPage)
public class BulletScreenDialogActivity extends BaseActivity<ActivityBulletScreenDialogBinding> {

    @Autowired
    String contentText;

    @Autowired(injector = ViewModelInjector.class)
    BulletScreenDialogViewModel viewModel;

    @Autowired(injector = EventControllerInjector.class)
    BulletScreenDialogController controller;

    @Override
    public int layoutRid() {
        return R.layout.activity_bullet_screen_dialog;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ThemeUtil.setWindowGravityBottom(this, ViewGroup.LayoutParams.WRAP_CONTENT);

        controller.onAddition(viewModel);
        viewModel.setContentText(contentText);

        showKeyBoard(viewDataBinder().contentText);
    }

    private void showKeyBoard(final EditText textView) {
        textView.postDelayed(() -> {
            textView.requestFocus();
            UIUtil.showKeyboard(this, textView);
        }, 100);
    }

    public void hideKeyBoard() {
        View view = getCurrentFocus();
        if(ObjectUtil.nonNull(view)) {
            UIUtil.hideKeyboard(this, view);
        }
    }

}
